package concurrency.chapter4;

public class DaemonThread {
    public static void main(String[] args) {
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    System.out.println(Thread.currentThread().getName() + "running");
                    Thread.sleep(100000);
                    System.out.println(Thread.currentThread().getName() + "done");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };//new
        t.setDaemon(true);//设置守护线程，需要在start之前调用，main线程生命周期结束，创建的守护线程也跟着结束
        t.start();//runnable -> running -> dead -> blocked

        try {
            Thread.sleep(10_000); //JDK1.7以后支持的一种写法
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "***");

    }
}
